<script>
import config from './config.js'; // 导入配置文件

export default {
  onLaunch: function() {
    console.log('App Launch')
  },
  onShow: function() {
    console.log('App Show')
  },
  onHide: function() {
    console.log('App Hide')
    // 小程序退出时删除会话
    this.deleteSessionOnExit();
  },
  methods: {
    // 退出时删除会话的方法
    async deleteSessionOnExit() {
      try {
        const sessionId = uni.getStorageSync('qaSessionId');
        if (sessionId) {
          await uni.request({
            url: `${config.baseUrl}/smartqa/deleteSession`,
            method: 'POST',
            header: {
              'Content-Type': 'application/json',
              'Authorization': uni.getStorageSync('token') || ''
            },
            data: {
              sessionId: sessionId
            }
          });
          uni.removeStorageSync('qaSessionId');
        }
      } catch (error) {
        console.error('退出时删除会话失败', error);
      }
    }
  }
}
</script>

<style>
	/*每个页面公共css */
</style>
